import request from '@/utils/request'

// 用户管理
export function getUserList(params) {
  return request({
    url: '/api/users/list',
    method: 'get',
    params
  })
}

export function addUser(data) {
  return request({
    url: '/api/users',
    method: 'post',
    data
  })
}

export function updateUser(id, data) {
  return request({
    url: `/api/users/${id}`,
    method: 'put',
    data
  })
}

export function deleteUser(id) {
  return request({
    url: `/api/users/${id}`,
    method: 'delete'
  })
}

export function getUserRoles(userId) {
  return request({
    url: `/api/users/${userId}/roles`,
    method: 'get'
  })
}

export function assignUserRoles(userId, roleIds) {
  return request({
    url: `/api/users/${userId}/roles`,
    method: 'post',
    data: roleIds
  })
}

export function resetUserPassword(userId) {
  return request({
    url: `/api/users/${userId}/reset-password`,
    method: 'post'
  })
}

// 角色管理
export function getRoleList(params) {
  return request({
    url: '/api/roles/list',
    method: 'get',
    params
  })
}

export function getAvailableRoles() {
  return request({
    url: '/api/roles/available',
    method: 'get'
  })
}

export function addRole(data) {
  return request({
    url: '/api/roles',
    method: 'post',
    data
  })
}

export function updateRole(id, data) {
  return request({
    url: `/api/roles/${id}`,
    method: 'put',
    data
  })
}

export function deleteRole(id) {
  return request({
    url: `/api/roles/${id}`,
    method: 'delete'
  })
}

export function getRoleMenus(roleId) {
  return request({
    url: `/api/roles/${roleId}/menus`,
    method: 'get'
  })
}

export function assignRoleMenus(roleId, menuIds) {
  return request({
    url: `/api/roles/${roleId}/menus`,
    method: 'put',
    data: menuIds
  })
}

// 菜单管理
export function getMenuList(params) {
  return request({
    url: '/api/menus/list',
    method: 'get',
    params
  })
}

export function getMenuTree() {
  return request({
    url: '/api/menus/tree',
    method: 'get'
  })
}

export function addMenu(data) {
  return request({
    url: '/api/menus',
    method: 'post',
    data
  })
}

export function updateMenu(id, data) {
  return request({
    url: `/api/menus/${id}`,
    method: 'put',
    data
  })
}

export function deleteMenu(id) {
  return request({
    url: `/api/menus/${id}`,
    method: 'delete'
  })
}

export function getMenuDetail(id) {
  return request({
    url: `/api/menus/${id}`,
    method: 'get'
  })
} 